import React, { Component } from 'react';

class Child1 extends Component {
  render () {
    return (
      <div>
        { this.props.count }
        <button onClick={ () => this.props.changeCount() }>child1 - 加</button>
      </div>
    )
  }
}
class Child2 extends Component {
  render () {
    return (
      <div>
        { this.props.count }
        <button onClick={ () => this.props.changeCount() }>child2 - 加</button>
      </div>
    )
  }
}
class App extends Component {
  state = { count: 1 }
  changeCount = () => { this.setState({ count: this.state.count + 1 }) }
  render() {
    return (
      <div>
        <Child1 count = { this.state.count } changeCount = { this.changeCount }/>
        <hr/>
        <Child2 count = { this.state.count } changeCount = { this.changeCount }/>
      </div>
    );
  }
}

export default App;